<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*,java.text.SimpleDateFormat"%>
<%@ taglib uri="/WEB-INF/commontags.tld" prefix="common" %><%--페이징처리tag--%>
<jsp:include page="common/header.jsp"></jsp:include>
<%

UserSession usersession = (UserSession)session.getAttribute("user");
//String ent_id 			= (String)session.getAttribute("ent_id");

String connGroup 	= "";
String user_id 		= "";
if(usersession!=null){
	connGroup 	= CmmUtil.nvl(usersession.getConnGroup(),"0");
	user_id 	= CmmUtil.nvl(usersession.getUser_id(),"");
}

System.out.println("connGroup======>"+connGroup);
System.out.println("user_id======>"+user_id);

String keyword_gb 	= CmmUtil.nvl(request.getParameter("search_gb"),"");
String keyword 		= CmmUtil.nvl(request.getParameter("search_word"),"");
String line_number	= CmmUtil.nvl(request.getParameter("line_number"),"10");

String present_Year = String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR));
//GregorianCalendar에서 1월 return 값이 0이므로 Month에는  1을 더해주어야 함
String present_Month = String.valueOf(GregorianCalendar.getInstance().get(Calendar.MONTH)+1); 
String present_Date = String.valueOf(GregorianCalendar.getInstance().get(Calendar.DATE));

if(present_Month.length() == 1){
	present_Month = "0" + present_Month; //01월,02월 ..... 09월
}

GregorianCalendar g = new GregorianCalendar();
g.add(Calendar.MONTH, 0);

String befor_Month = String.valueOf(g.get(Calendar.MONTH));

if(befor_Month.length() == 1){
	befor_Month = "0" + befor_Month; //01월,02월 ..... 09월
}

if(present_Date.length() == 1){
	present_Date = "0" + present_Date; //01일,02일 ..... 09일
}

//start_dt,close_dt,selected_year,selected_month 의 값에 받아오는 인자가 없을 경우 default로 현재 시간을 Setting
String start_date 		= CmmUtil.nvl(request.getParameter("start_date"),present_Year + befor_Month + present_Date);
String close_date 		= CmmUtil.nvl(request.getParameter("close_date"),present_Year + present_Month + present_Date);


System.out.println("keyword ======> " + keyword);

java.util.Date date = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");     
String today = formatter.format(date); 



//페이징 처리 Start
	//페이지 표시정보 받기 혹은 검색입력창
	String curr_page = request.getParameter("curr_page");
	if (curr_page == null || curr_page.equals(""))
		curr_page = "1";
	String one_page = request.getParameter("one_page");
	if (one_page == null || one_page.equals(""))
		one_page = "10";
	String one_group = request.getParameter("one_group");
	if (one_group == null || one_group.equals(""))
		one_group = "10";
	
	String total_count = CmmUtil.nvl(request.getParameter("total_count"),"0");
	
	//페이징 처리 End	
	
	/*
	//회차검색 위한 날짜정보 가지고 오기
	HashMap map_date = new HashMap();
	HashMap map1_date = null;
	ArrayList list_date = new ArrayList();
	CommonDaoService commonservice_date = new CommonDaoService("ComSearchDateDao");	
	map_date.put("user_id",user_id);		
	list_date = (ArrayList)commonservice_date.commonDaoMethod(map_date);
	*/
	
	HashMap map = new HashMap();
	HashMap map1 = null;
	ArrayList list = new ArrayList();
	
	if(!start_date.equals("") && !close_date.equals("")){
		CommonDaoService commonservice = new CommonDaoService("Com0202lp01Dao");
		map.put("connGroup",connGroup);
		map.put("user_id",user_id);		
		map.put("start_date",start_date);
		map.put("close_date",close_date);	
		map.put("keyword_gb",keyword_gb);
		map.put("keyword",keyword);
		map.put("page_row",line_number);
		map.put("total_row",total_count);
		map.put("page_no",curr_page);
		
		list = (ArrayList)commonservice.commonDaoMethod(map);
		
		System.out.println(list);
	}
	
	int lect_amt_total = 0; //교육비
	int ret_amt_total = 0; //환급액
	int lect_sum_total = 0; //실비용
	
	
	if(list != null){
		if(list.size() > 0){
			total_count = (String)((HashMap)list.get(0)).get("total_row");
			
			if(((HashMap)list.get(0)).get("lect_amt_total").toString() != null){
				lect_amt_total = Integer.parseInt(((HashMap)list.get(0)).get("lect_amt_total").toString());
				ret_amt_total = Integer.parseInt(((HashMap)list.get(0)).get("ret_amt_total").toString());
				
				lect_sum_total = lect_amt_total - ret_amt_total;
			}
			
			System.out.println("total_count " + total_count);
			System.out.println("lect_sum_total " + lect_sum_total);			
		}
	}
	
	String app_str="";	
	
%>
<script>
function search(){
	var frm = document.mainfrm;
	frm.curr_page.value=1;
	frm.total_count.value=0;
	frm.method = "post";
	frm.action = "/jsp/com0202l_p01.jsp";
	frm.target="_self";
	frm.submit();
}

// 페이지 번호를 눌렸을때.
function go_page(page){
	var frm = document.mainfrm;
	frm.curr_page.value = page ;			
	frm.total_count.value = "<%=total_count%>";
	frm.method = "post";
	frm.action = "/jsp/com0202l_p01.jsp";
	frm.target="_self";
	frm.submit();
}

//엑셀다운로드
function excel_down(){
	var frm = document.mainfrm;
	frm.action = "/jsp/com0202l_p01_excel.jsp";
	frm.target="_blank";
	frm.method = "post";
	frm.submit();	
}
</script>
<body>
<table width="992" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td><!--top -->
    <jsp:include page="common/top_menu.jsp"></jsp:include> 
    <!-- //top -->
    <!-- contents area -->
<form name="mainfrm" method="post" action="javascript:search();">
<input type="hidden" name="curr_page" value="<%=curr_page%>">
<input type="hidden" name="total_count" value="<%=total_count%>">

  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="180" valign="top">
    	<jsp:include page="left/com0201l_p04.jsp"></jsp:include>
    </td>
    <td width="21" valign="top">&nbsp;</td>
    <td valign="top" style="margin:0 0 15px 0;">
    	 <table width="790px"  border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="font-size:14px; color:#3b70a2; font-weight:bold; border-bottom:2px solid #c8c8c8; padding:0 0 5px 0;" align="left"><img src="/images/sub_icon1.jpg"  alt="" border="0">&nbsp;- 환급신청보고</td>
            </tr>
        </table>
        <table width="790px"  border="0" cellpadding="0" cellspacing="0" style="margin:5px 0 0 0;">
        	<tr>
            	<td align="left"><img src="/images/archive.gif"  alt="" border="0" /> 학습 시작일&nbsp;&nbsp;
                <input type="text" name="start_date" id="start_date" class="textbox" value="<%=start_date %>"/>
				<script language=javascript>
				var basicCal = new calendar("FIELD:document.mainfrm.start_date;FORMAT:2;DELIMITER:;");
    			basicCal.writeCalendar();
    			</script>
				~
				<input type="text" name="close_date" id="close_date" class="textbox" value="<%=close_date %>"/>
				<script language=javascript>
				var basicCal = new calendar("FIELD:document.mainfrm.close_date;FORMAT:2;DELIMITER:;");
    			basicCal.writeCalendar();
    			</script>   
				&nbsp;&nbsp;<a href="javascript:search()"><img src="/images/bt_search1.gif" align="absmiddle" /></a>
                </td>
                <td align="right"><a href="javascript:excel_down()"><img src="/images/btn_save_excel2.gif" align="absmiddle" /></a></td>
            </tr>
        </table>
        <table>
        	<tr>
            	<td>
                	<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="table19p">
                  <tr>
                    <td rowspan="2" class="table_th">교육기간</td>
                    <td rowspan="2" class="table_th">수강인원</td>
                    <td colspan="4" class="table_th">기수 과정</td>
                    
                    <td rowspan="2" class="table_th">총교육비</td>
                  </tr>
                  <tr>
                    <td class="table_td2Line">인원수</td>
                    <td class="table_td2Line">교육비</td>
                    <td class="table_td2Line">환급액</td>
                    <td class="table_td2Line">실비용</td>
                   
                  </tr>
			<%if(list.size() == 0){ %>
				  <tr>
                    <td colspan=9 align=center>회차검색을 해주세요.</td>                    
                  </tr>	
			<%}else{ %>
                  <tr>
                    <td><%=start_date %> ~ <%=close_date %></td>
                    <td><%=total_count %></td>
                    <td><%=total_count %></td>
                    <td><%=lect_amt_total %></td>
                    <td><%=ret_amt_total %></td>
                    <td><%=lect_sum_total %></td>
                    
                    <td><%=lect_amt_total %></td>
                  </tr>
			<%} %>
                </table>
                </td>
            </tr>
        </table>
		<%if(list.size() > 0){ %>
         <table width="100%"  border="0" cellpadding="0" cellspacing="0">
       	<tr>
        <td align="left">              
        
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
         	<tr>
            	<td align="right">
                	<select name="search_gb">
						<option value="" >검색조건</option>
                 		<option value="1" <%if(keyword_gb.equals("1")){%>selected<%}%>>성명</option>
                 		<option value="2" <%if(keyword_gb.equals("2")){%>selected<%}%>>과정명</option>
                   </select>
                    <input type="text" name="search_word" class="textbox" required="required" hname="검색어" value="<%=keyword %>" />
                    <a href="javascript:search()"><img src="/images/bt_search2.gif" align=absmiddle /></a>
                </td>
            </tr>
        	<tr>
            	<td align="left">
                 <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="main_table4">
                  <tr>
                    <td class="table_th">번호</td>                    
                    <td class="table_th">과정명</td>
                    <td class="table_th">성명</td>
					 <td class="table_th">주민번호</td>
					 <td class="table_th">교육기간</td>
					 <td class="table_th">훈련시간</td>
					 <td class="table_th">환급액</td>
					 <td class="table_th">수료번호</td>
					                  
                  </tr>
			<%
			String str_socno = null;			
			
			for(int i=0; i<list.size(); i++){
            	map1 			= (HashMap)list.get(i);       	
            	
            	str_socno = Crypto.DecodeBySType(map1.get("soc_no").toString());
			%>
                  <tr>
                    <td><%=map1.get("r_num") %></td>
					<td><%=map1.get("poi_nm2") %></td>
                    <td><%=map1.get("login_nm") %></td>                    
                    <td><%=str_socno %></td>
					<td><%=map1.get("std_start_dt") %> ~ <%=map1.get("std_close_dt") %></td>
					<td><%=map1.get("std_tm") %></td>
					<td><%=map1.get("ret_amt") %></td>
					<td><%=map1.get("fin_no") %></td>					
					                
                  </tr>
			<%} %>
                  
                </table>   
                </td>
            </tr>
        </table>
        </td>
      </tr>
     </table>
		<%} %>
        </td>
      </tr>
     </table>
        
        
        <common:pagelistnew currPage="<%=curr_page%>" total="<%=total_count%>" onePage="<%=one_page%>" oneGroup="<%=one_group%>"/>
	</td>
  </tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<td height=10>
	</td>
</table>
	<jsp:include page="common/footer.jsp"></jsp:include>
	</td>
  </tr>
</form>
</table>

<iframe name='hide_src'  width='0' height='0' SCROLLING='AUTO' frameborder='0'></iframe>
</body>
</html>
